using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Episode01
{
    public class Gun : MonoBehaviour
    {
        /// <summary>
        /// 枪口
        /// </summary>
        public Transform muzzle;
        /// <summary>
        /// 子弹预制体
        /// </summary>
        public Projectile projectile;
        /// <summary>
        /// 子弹发射间隔时间
        /// </summary>
        public float msBetweenShots = 100;
        /// <summary>
        /// 子弹出膛速度
        /// </summary>
        public float muzzleVelocity = 35;

        float nextShotTime;

        public void Shoot()
        {
            if(Time.time > nextShotTime)
            {
                nextShotTime = Time.time + msBetweenShots / 1000;
                Projectile newProjectile = Instantiate(projectile, muzzle.position, muzzle.rotation) as Projectile;
                newProjectile.SetSpeed(muzzleVelocity);
            }
        }
    }
}